package com.sharedlease.controller;


import com.sharedlease.entity.Share_class;
import com.sharedlease.entity.R;
import com.sharedlease.service.Share_classService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴钟富
 * @since 2021-03-22
 */
@RestController
@Api(tags = "共享产品（类）相关接口")
@RequestMapping("/share-class")
public class Share_classController {
    @Autowired
    public Share_classService share_classService;
    @GetMapping("/getById/{id}")
    @ApiOperation("根据一个id查询共享产品（类）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要查询的共享产品（类）id", defaultValue = "1"),

    }
    )
    public Share_class getById(@PathVariable Long id) {
        Share_class share_class = share_classService.getById(id);
        return share_class;
    }

    @GetMapping("/list")
    @ApiOperation("查询全部共享产品（类）")
    public List<Share_class> list() {
        List<Share_class> list = share_classService.list(null);
        return list;
    }

    @PostMapping("/save")
    @ApiOperation("新增一类共享产品")
    public R save(@RequestBody Share_class share_class) {

        return R.operate(share_classService.save(share_class));
    }

    @PutMapping("/update")
    @ApiOperation("根据id更改一类共享产品")
    public R update(@RequestBody Share_class share_class) {
        if (share_classService.updateById(share_class)) {
            return R.ok();
        }
        return R.error();
    }


    @DeleteMapping("/removeById/{id}")
    @ApiOperation("根据id删除一类共享产品")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "要删除的共享产品（类）id", defaultValue = "-1"),

    }
    )
    public R removeById(@PathVariable Long id) {

        return R.operate(share_classService.removeById(id));
    }

}

